use serde::{Deserialize, Serialize};
use serde_yaml;
use std::fs::File;
//use std::collections::HashMap;
//use std::io::Read;
use std::fmt::{Debug};

#[derive(Debug, Serialize, Deserialize)]
pub struct ConfigRemote {
    name: String,
    fetch: String,
    review: Option<String>,
    push: Option<String>
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ConfigDefault {
    remote: String,
    revision: String,
    sync_c: bool,
    sync_s: bool
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ConfigCommand {
    cmd: String,
    src: String,
    dst: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ConfigProject {
    name: String,
    path: Option<String>,
    remote: Option<String>,
    revision: Option<String>,
    sync_c: Option<bool>,
    sync_s: Option<bool>,
    commands: Option<Vec<ConfigCommand>>,
}



#[derive(Debug, Serialize, Deserialize)]
pub struct Config {
    remote: Vec<ConfigRemote>,
    default: ConfigDefault,
    project: Vec<ConfigProject>,
}


pub fn manifest_parse(file_path: &str) ->Result<Config, Box<dyn std::error::Error>> {
    let file = File::open(file_path)?;
    let config = serde_yaml::from_reader(file)?; 

    Ok(config)
}
